#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#define MAX_N 1025
using namespace std;
#define lowbit(x) ((x)&(-x))

int a[MAX_N][MAX_N];
int ins,S;
void update(int x,int y, int deleta)
{
    for (int i = x ; i<= S ; i+=lowbit(i))
    {
        for (int j = y ; j <= S ; j+=lowbit(j))
        {
            a[i][j] += deleta;
        }
    }
}


int sum(int x,int y)
{
    int result = 0;
    for (int i = x ; i>0 ; i-=lowbit(i))
    {
        for (int j = y ; j >0 ; j -=lowbit(j) )
        {
            result += a[i][j];
        }
    }

    return result;
}

int main()
{
   // freopen("1195.txt","r",stdin);
    cin >> ins >> S;
    memset(a,0,sizeof(a));

    int x,y,deleta ;
    while(cin >> ins)
    {
        if (ins == 1)
        {
            scanf("%d%d%d",&x,&y,&deleta);
            x++;
            y++;
            update(x,y,deleta);
        }
        if (ins==2)
        {
            int L,B,R,T;
            scanf("%d%d%d%d",&L,&B,&R,&T);
            L++,B++,R++,T++;
            cout << sum(R,T) - sum(R,B-1) -sum(L-1,T) + sum(L-1,B-1)<<endl;
        }
        if (ins == 3)
        {
            break;
        }
    }
    return 0;
}
